﻿using AutoMapper;
using MediatR;
using MyMES.Domain.yjb;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.settingCommand;

namespace MyMES.Writer.API.Application.CommendHandlers.settingCommand
{
    public class DelTaskInfoCommandHandlers : IRequestHandler<DelTaskInfoCommand, APIResult<int>>
    {
        private readonly IBaseRepository<TaskInfo> accreop;
        private readonly IMapper mapper;

        public DelTaskInfoCommandHandlers(IBaseRepository<TaskInfo> accreop, IMapper mapper)
        {
            this.accreop = accreop;
            this.mapper = mapper;
        }
        /// <summary>
        /// 任务-删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<int>> Handle(DelTaskInfoCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code = APIEnum.删除成功;
            result.Msg = "删除成功";
            var process = mapper.Map<TaskInfo>(request);
            string sql = " update TaskInfo set  IsDelete=true where TaskInfoId=@TaskInfoId;";
            await accreop.Update(process, sql);
            return result;
        }
    }
}
